package com.tkm.builtinTypes.collections

fun main() {
    //  List：不可变List，无法添加、删除元素
    //  MutableList：可变List
    val intList: List<Int> = listOf(1, 2, 3, 4)
//    intList.add(5)
//    intList.remove(1)
    val intList2: MutableList<Int> = mutableListOf(1, 2, 3, 4)
    intList2.add(5)
    intList2.remove(1)

    //  Map/MutableMap
    val map: Map<String, Any> = mapOf("name" to "Bread", "age" to 24)
    val map2: MutableMap<String, Any> = mutableMapOf("name" to "Bread", "age" to 24)
    map2["height"] = 1.74

    //  ArrayList：动态数组，java.util.ArrayList
    val stringList = ArrayList<String>()
    stringList.add("Hello")
    stringList.add("World")
    println(stringList)

    for (i in 0..10) {
        stringList.add("number: $i")
    }

    for (i in 0..10) {
        stringList += "number: $i"
    }

    //  HashMap：java.util.HashMap
    val hashMap = HashMap<String, Any>()
    hashMap["name"] = "Bread"
    hashMap["age"] = 24
    hashMap["height"] = 1.74

    //  Pair
    val pair = "name" to "Bread"
    val pair2 = Pair("name", "Bread")
    //  分别取值
    val k = pair.first
    val v = pair.second
    //  解构语法
    val (k2, v2) = pair2

    //  Triple
    val triple = Triple("x", 1, true)
    //  分别取值
    val first = triple.first
    val second = triple.second
    val third = triple.third
    //  解构语法
    val (f, s, t) = triple
}
